﻿using System;
using System.Collections.Generic;
using System.Text;
using Watchdog.Bll.Factory;

namespace Watchdog.Bll.Base {

    public partial class DefinitionBase {

        #region [ Local variables ]
        Facade.Definition intdata;
        #endregion

        #region [ Constructor(s) ]
        internal DefinitionBase () {
            intdata = new Watchdog.Facade.Definition ();
        }
        internal DefinitionBase (Facade.Definition definition) : base () {
            intdata = definition;
        }
        #endregion

        #region [ Field Properties ]
        public int Id {
            get { return intdata.Id; }
        }
        public virtual string Name {
            get { return intdata.Name; }
            set { intdata.Name = value; }
        }
        public virtual bool IsMultipleTarget {
            get { return intdata.IsMultipleTarget; }
            set { intdata.IsMultipleTarget = value; }
        }
        public virtual string Description {
            get { return intdata.Description; }
            set { intdata.Description = value; }
        }
        public virtual int Type {
            get { return intdata.Type; }
            set { intdata.Type = value; }
        }
        public virtual DateTime Created {
            get { return intdata.Created; }
            set { intdata.Created = value; }
        }
        public virtual DateTime Modified {
            get { return intdata.Modified; }
            set { intdata.Modified = value; }
        }
		#endregion
		
        #region [ Data Methods ]
        public void Update () {
            if (Id == -1)
                DefinitionFactory.Insert ( this );
            else
                DefinitionFactory.Update ( this );
        }

        public void Delete () {
            DefinitionFactory.Delete ( this );
        }
        #endregion

		#region [ Many to many relations native type ]

		#endregion

		#region [ Add & Remove methods for many to many relations native type ]

		#endregion
		
        internal Facade.Definition IntData {
            get { return intdata; }
            set { intdata = value; }
        }

        #region [ Equality ]
        public override int GetHashCode () {
            return Id;
        }
        public static bool operator == ( DefinitionBase lt1, DefinitionBase lt2 ) {
            if (System.Object.ReferenceEquals ( lt1, lt2 ))
                return true;

            if ((object)lt1 == null || (object)lt2 == null)
                return false;
            return lt1.Equals ( lt2 );
        }
        public static bool operator != ( DefinitionBase lt1, DefinitionBase lt2 ) {
            if (lt1 == null || lt2 == null)
                return false;
            return !(lt1 == lt2);
        }

        public override bool Equals ( object obj ) {
            if (!(obj is DefinitionBase))
                return false;
            return (this.CompareTo ( obj ) == 0);
        }

        private int CompareTo ( object obj ) {
            if (!(obj is DefinitionBase)) {
                throw new ArgumentException ( "A 'DefinitionBase' object is required for comparison." );
            }
            return this.Id.CompareTo ( ((DefinitionBase)obj).Id );
        }
        #endregion

	}
}
